package org.netEase.controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.File;
import com.jspsmart.upload.Files;
import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;


import org.netEase.dao.*;
import org.netEase.dao.impl.*;
import org.netEase.entity.*;

@WebServlet(urlPatterns = { "/backstageManager/zhutiadd.shtml" })

public class zhutiAdd extends HttpServlet {
   @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	   SmartUpload smartUpload = new SmartUpload();
		smartUpload.initialize(this, request, response);
		try {
			smartUpload.upload();
		} catch (SmartUploadException e) {
			e.printStackTrace();
		}
		Request req = smartUpload.getRequest();
		String name = req.getParameter("name");
		String ztImages=req.getParameter("ztImages");
		Files files = smartUpload.getFiles();
		File file = files.getFile(0);
		zhuti zhu=new zhuti();
		zhu.setName(name);
		zhu.setZtImages(ztImages);
		
		if(file.isMissing() == false){
			try {
				file.saveAs("./images/index/"+file.getFileName());
			} catch (SmartUploadException e) {
				e.printStackTrace();
			}
			
			zhu.setZtImages(file.getFileName());

		}
		zhutiDao zhudao=new zhutiDaoImpl();
		int result=zhudao.add(zhu);
		
		if(result > 0){
			response.sendRedirect(request.getContextPath() + "/backstageManager/productbrand.shtml");
		}
}
   @Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(request, response);
	}
}
